package com.broadcaster.broadcaster.core.config;


import com.broadcaster.broadcaster.core.BroadcasterServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
*
*
* */
@Configuration
public class BroadcasterConfig {

    @Autowired
    public  RedisConnectionFactory connectionFactory;

    @Bean
    public  RedisMessageListenerContainer container(MessageListenerAdapter listenerAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(listenerAdapter, new PatternTopic("map"));
        return container;
    }

    /**
     * @param listener 自定义接收消息类和方法固定配置
     * @return
     */
    @Bean
    MessageListenerAdapter listenerAdapter(BroadcasterServer listener) {
        return new MessageListenerAdapter(listener, "doMap");
    }







}
